<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src='vue.js'></script>
</head>
<body>
	<div id="app">
		<input type="text" v-model="inputValue">
		<button @click="handleBtnClick">提交</button>
		<ul>
			<todo-item 
					:content="item" 
					:index="index" 
					v-for="(item, index) in list" 
					@delete="handleItemDelete">
			</todo-item>	
		</ul>
	</div>

	<script>

		var todoItem = {
			props: ['content', 'index'],
			template: '<li @click="handleItemClick">{{content}}</li>',
			methods: {
				handleItemClick: function () {
					this.$emit('delete', this.index);
				}
			}
		}

		var app = new Vue({
			el: '#app',
			components: {
				todoItem: todoItem
			},
			data: function () {
				return {
					inputValue: '',
					list: ['第一课程内容', '第二课程内容']
				}
			},
			methods: {
				handleBtnClick: function () {
					if (this.inputValue !== '') {
						this.list.push(this.inputValue);
						this.inputValue = '';
					}	
				},
				handleItemDelete: function (index) {
					this.list.splice(index, 1);
				}
			}
		})

		
	</script>
</body>
</html>